package com.middlegroup.payadmin.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.middlegroup.payadmin.mapper.RoleMerchantMapMapper;
import com.middlegroup.payadmin.mapper.RoleOperateMapper;
import com.middlegroup.payadmin.pojo.po.Merchant;
import com.middlegroup.payadmin.pojo.po.RoleMerchantMap;
import com.middlegroup.payadmin.service.RoleMerchantMapService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色商户映射表(支持一个角色有多个商户的数据权限) 服务实现类
 * </p>
 *
 * @author pc123
 * @since 2019-01-04
 */
@Service
public class RoleMerchantMapServiceImpl extends ServiceImpl<RoleMerchantMapMapper, RoleMerchantMap> implements RoleMerchantMapService {

    @Resource
    private RoleMerchantMapMapper roleMerchantMapMapper;

    @Override
    @Cacheable(value = "role_merchant_map",key = "#p0.toString()",unless = "#result eq null")
    public List<String> getMerchantCodeByRoleCode(String roleCode) {
        return roleMerchantMapMapper.getMerchantCodeByRoleCode(roleCode);
    }

    @Override
    public List<Merchant> getRoleMerchants(String code) {
        return roleMerchantMapMapper.getRoleMerchants(code);
    }

    @Override
    public int saveOrUpdate(RoleMerchantMap roleMerchantMap) {
        return roleMerchantMapMapper.saveOrUpdate(roleMerchantMap);
    }
}
